public class Demo {
    public int[] searchRange(int[] nums, int target) {
        int mid = 0;
        int left = 0;
        int right = nums.length - 1;
        if (nums == null || nums.length == 0){
            return new int[]{-1, -1};
        }
        while (left < right && nums[mid] != target){
            mid = (left + right) / 2;
            if (nums[mid] < target){
                left = mid + 1;
            }else if (nums[mid] > target){
                right = mid - 1;
            }
        }
        if (nums[mid] != target) return new int[]{-1, -1};
        left = mid;
        right = mid;
        while (nums[right + 1] == target) right++;
        while (nums[left - 1] == target) left--;
        return new int[]{left, right};
    }
}
